home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DPanel.cpp < prev    next >
Text File  |  1996-07-05  |  17KB  |  716 lines

  1. // DPanel.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "Dvibrant.h"
  6. #include "DWindow.h"
  7. #include "DPanel.h"
  8. #include "DControl.h"
  9. #include "DIconLib.h"
  10. #include "DCommand.h"
  11. #include "DTracker.h"
  12.  
  13.  
  14. extern "C" void panelDrawProc(Nlm_PaneL    item)
  15. {
  16.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  17.     if (obj)  obj->Draw();
  18. }
  19.  
  20. extern "C" void panelVscrollProc(Nlm_BaR sb, Nlm_SlatE s, short newval, short oldval)
  21. {
  22.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)s);
  23.     if (obj) obj->Scroll(true, obj, newval, oldval);
  24. }
  25.  
  26. extern "C" void panelHscrollProc(Nlm_BaR sb, Nlm_SlatE s, short newval, short oldval)
  27. {
  28.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)s);
  29.     if (obj) obj->Scroll(false, obj, newval, oldval);
  30. }
  31.  
  32. extern "C" void panelClickProc(Nlm_PaneL item, Nlm_PoinT mouse)
  33. {
  34.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  35.     if (obj) obj->Click(mouse);
  36. }
  37.  
  38. extern "C" void panelDragProc(Nlm_PaneL item, Nlm_PoinT mouse)
  39. {
  40.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  41.     if (obj) obj->Drag(mouse);
  42. }
  43.  
  44. extern "C" void panelHoldProc(Nlm_PaneL item, Nlm_PoinT mouse)
  45. {
  46.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  47.     if (obj) obj->Hold(mouse);
  48. }
  49.  
  50. extern "C" void panelReleaseProc(Nlm_PaneL item, Nlm_PoinT mouse)
  51. {
  52.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  53.     if (obj) obj->Release(mouse);
  54. }
  55.  
  56. extern "C" void panelCharProc(Nlm_SlatE s, Nlm_Char c)
  57. {
  58.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)s);
  59.     if (obj) obj->CharHandler(c);
  60. }
  61.  
  62.  
  63. //class DPanel : public DView
  64.  
  65. DPanel::DPanel(long id, DView* itsSuperior, short pixwidth, short pixheight, PanelKind kind) :
  66.         DView( id, NULL, kPanel, itsSuperior),
  67.         fMouseStillDown(false), fTracker(NULL),
  68.         fPanelKind(kind) 
  69. {
  70.     switch (kind) {
  71.     
  72.         case simple:
  73.             fPanel= Nlm_SimplePanel((Nlm_WindoW)itsSuperior->GetNlmObject(), 
  74.               pixwidth, pixheight, panelDrawProc);
  75.             break;
  76.             
  77.         case autonomous:
  78.             fPanel= Nlm_AutonomousPanel((Nlm_WindoW)itsSuperior->GetNlmObject(),
  79.               pixwidth, pixheight, 
  80.                 panelDrawProc, panelVscrollProc, panelHscrollProc, 0/*extra*/, NULL/*panelResetProc*/, 
  81.                 NULL/*panelGraphProcPtr*/);
  82.             Nlm_SetSlateChar( (Nlm_SlatE) fPanel, panelCharProc);
  83.             // ?? make autonomous panel a new class ??
  84.             break;
  85.             
  86.         case slatebound:
  87.             fPanel= Nlm_CustomPanel((Nlm_SlatE)itsSuperior->GetNlmObject(), panelDrawProc, 
  88.                 0/*extra*/, NULL/*panelResetProc*/);
  89.             break;
  90.             
  91.         case subclasscreates:
  92.             return; // this null case used by DDocPanel
  93.         }
  94.     Nlm_SetPanelClick(fPanel, panelClickProc, panelDragProc, panelHoldProc, panelReleaseProc);
  95.     this->SetNlmObject(fPanel);    
  96. }
  97.  
  98. extern "C" void Nlm_ClearPanelData(Nlm_PaneL p); /* in vibslate.c */
  99.  
  100. DPanel::~DPanel()
  101. {
  102.         // this is to stop XWin callbacks -- don't think it is working ...
  103.     //Nlm_ClearPanelData( fPanel);
  104. }
  105.  
  106. void DPanel::SetSlateBorder(Boolean turnon) 
  107. {
  108.      if (fPanelKind == autonomous) 
  109.          Nlm_SetSlateBorder((Nlm_SlatE)fPanel, turnon);  
  110. }
  111.  
  112.  
  113. //void DPanel::Draw() { } // abstract class, user must subclass
  114.  
  115. void DPanel::Scroll(Boolean vertical, DView* scrollee, long newval, long oldval)
  116. {
  117. }
  118.  
  119.  
  120.  
  121. void DPanel::SetTracker( DTracker* mouseTracker)
  122. {
  123.     //if (fTracker) fTracker->SetTracker(mouseTracker);
  124.     fTracker= mouseTracker;
  125. }
  126.  
  127. Nlm_Boolean DPanel::IsDoneTracking()
  128. {
  129.     if (fTracker) return !fMouseStillDown;
  130.     else return true;
  131. }
  132.  
  133. void DPanel::Click(Nlm_PoinT mouse)
  134. {
  135.     // this is always called before Drag/Hold/Release
  136.     // Release is only called if Drag/Hold are called (only if mouse is down for a while)
  137.     fMouseStillDown= false;
  138.     if (fTracker) fTracker= fTracker->Start( mouse);
  139. }
  140.  
  141. void DPanel::Drag(Nlm_PoinT mouse)
  142. {
  143.     fMouseStillDown= true;
  144.     if (fTracker) fTracker= fTracker->Continue( mouse, true);
  145. }
  146.  
  147. void DPanel::Hold(Nlm_PoinT mouse)
  148. {
  149.     fMouseStillDown= true;
  150.     if (fTracker) fTracker= fTracker->Continue( mouse, false);
  151. }
  152.  
  153. void DPanel::Release(Nlm_PoinT mouse)
  154. {
  155.     fMouseStillDown= false;
  156.     if (fTracker) fTracker= fTracker->Finish( mouse);
  157.     if (fTracker) fTracker->Process(); // DoIt, if the command is still here...
  158. }
  159.  
  160. void DPanel::TrackMouse( short aTrackPhase,
  161.                     Nlm_PoinT& anchorPoint, Nlm_PoinT& previousPoint,
  162.                     Nlm_PoinT& nextPoint,    Nlm_Boolean mouseDidMove)
  163. {
  164. }
  165.  
  166. void DPanel::TrackFeedback( short aTrackPhase,
  167.                     const Nlm_PoinT& anchorPoint, const Nlm_PoinT& previousPoint,
  168.                     const Nlm_PoinT& nextPoint, Nlm_Boolean mouseDidMove, Nlm_Boolean turnItOn)
  169. {
  170. }
  171.  
  172.  
  173.  
  174. void DPanel::CharHandler(char c) 
  175. {
  176. }
  177.  
  178.  
  179. //class DAutoPanel : public DPanel
  180.  
  181. DAutoPanel::DAutoPanel(long id, DView* itsSuperior, short pixwidth, short pixheight,
  182.             Boolean hasVscroll, Boolean hasHscroll) :
  183.         DPanel(id, itsSuperior, pixwidth, pixheight, DPanel::subclasscreates)
  184. {
  185.     fPanelKind = DPanel::autonomous;
  186.     Nlm_SltScrlProc vproc= NULL;
  187.     Nlm_SltScrlProc hproc= NULL;
  188.     if (hasVscroll) vproc= panelVscrollProc;
  189.     if (hasHscroll) hproc= panelHscrollProc;
  190.     fPanel= Nlm_AutonomousPanel((Nlm_WindoW)itsSuperior->GetNlmObject(),
  191.       pixwidth, pixheight, panelDrawProc, vproc, hproc, 0/*extra*/, NULL/*panelResetProc*/, 
  192.         NULL/*panelGraphProcPtr*/);
  193.     Nlm_SetSlateChar( (Nlm_SlatE) fPanel, panelCharProc);
  194.     Nlm_SetPanelClick(fPanel, panelClickProc, panelDragProc, panelHoldProc, panelReleaseProc);
  195.     this->SetNlmObject(fPanel);    
  196. }
  197.  
  198.  
  199.  
  200.  
  201. //class DNotePanel : public DPanel
  202.  
  203.  
  204. extern "C" void notepDrawProc(Nlm_IcoN item)
  205. {
  206.     DNotePanel *obj= (DNotePanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  207.     if (obj) obj->Draw();
  208. }
  209.  
  210. extern "C" void notepInvalProc(Nlm_IcoN item, Nlm_Int2 newval, Nlm_Int2 oldval)
  211. {
  212.     DNotePanel *obj= (DNotePanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  213.     if (obj) obj->Invalid(newval, oldval);
  214. }
  215.  
  216. extern "C" void notepClickProc(Nlm_IcoN item, Nlm_PoinT mouse)
  217. {
  218.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  219.     if (obj) obj->Click(mouse);
  220. }
  221.  
  222. extern "C" void notepDragProc(Nlm_IcoN item, Nlm_PoinT mouse)
  223. {
  224.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  225.     if (obj) obj->Drag(mouse);
  226. }
  227.  
  228. extern "C" void notepHoldProc(Nlm_IcoN item, Nlm_PoinT mouse)
  229. {
  230.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  231.     if (obj) obj->Hold(mouse);
  232. }
  233.  
  234. extern "C" void notepReleaseProc(Nlm_IcoN item, Nlm_PoinT mouse)
  235. {
  236.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  237.     if (obj) obj->Release(mouse);
  238. }
  239.  
  240.  
  241.  
  242. DNotePanel::DNotePanel(long id, DView* itsSuperior, const char* title, 
  243.             short pixwidth, short pixheight, Nlm_FonT font, Justify just) :
  244.     DPanel( id, itsSuperior, pixwidth, pixheight, subclasscreates),
  245.     fText(NULL),
  246.     fTextLen(0),
  247.     fFont(font),
  248.     fJust(just),
  249.     fDimmed(false),
  250.     fEnabled(false)
  251. {
  252.     fText= StrDup(title);
  253.     if (fText) fTextLen= StrLen(fText);
  254.     if (pixwidth==0 || pixheight == 0) {
  255.         short width = pixwidth, height = pixheight;
  256.         this->GetSize(width,height);
  257.         if (pixwidth==0) pixwidth= width;
  258.         if (pixheight==0) pixheight= height;
  259.         }
  260.     fIconBut= Nlm_IconButton((Nlm_WindoW)itsSuperior->GetNlmObject(), pixwidth, pixheight, 
  261.         notepDrawProc, notepInvalProc, notepClickProc, notepDragProc, notepHoldProc, notepReleaseProc);
  262.     fPanel= (Nlm_PaneL) fIconBut;
  263.     this->SetNlmObject(fIconBut);    
  264. }
  265.  
  266.  
  267. void DNotePanel::SetTitle( char* title) 
  268.     Nlm_RecT r;
  269.     short width,height,curwidth,curheight;
  270.     
  271.     if (fText) MemFree(fText);
  272.     fText= StrDup(title);
  273.     if (fText) fTextLen= StrLen(fText);
  274.     else fTextLen= 0;
  275.     this->GetPosition(r); // ViewRect
  276.     width= curwidth= r.right - r.left;
  277.     height= curheight= r.bottom - r.top;
  278.     this->GetSize(width,height);
  279.     if (width>curwidth || height>curheight) {
  280.         r.right= r.left + width;
  281.         r.bottom= r.top + height; 
  282.         this->SetPosition(r);
  283.         }
  284.     
  285. }
  286.  
  287. char* DNotePanel::GetTitle(char* title, ulong maxsize) 
  288.     if (title==NULL) title= (char*)MemNew(maxsize);
  289.     StrNCpy( title, fText, maxsize);
  290.     return title;
  291. }
  292.  
  293. void DNotePanel::GetSize(short& width, short& height)
  294. {
  295.     long    nchars, pixwid;
  296.     char    *cp, *cp0;
  297.     short defwidth= width, defheight= height, nlines= 0;
  298.     Nlm_SelectFont(fFont);
  299.     cp0= fText;
  300.     width= 0;
  301.     if (fText) do {
  302.         nlines++;
  303.         cp= Nlm_StrChr(cp0, NEWLINE);  // '\n'  
  304.         if (cp) nchars= cp - cp0;
  305.         else nchars= fTextLen - (cp0 - fText);
  306.         pixwid= Nlm_TextWidth(cp0, nchars);
  307.         
  308.         if (defwidth && pixwid > defwidth) {
  309.             nchars= Min(nchars, 1 + defwidth / Nlm_MaxCharWidth());
  310.             pixwid= Nlm_TextWidth(cp0, nchars);
  311.             while (nchars > 0 && pixwid > defwidth) {
  312.             nchars--;
  313.             pixwid = Nlm_TextWidth (cp0, nchars);
  314.               }
  315.             }
  316.             
  317.         width= Max(width, pixwid);
  318.         if (cp) {
  319.             if (nchars < cp - cp0) cp0 += nchars; 
  320.             else cp0 = 1 + cp;
  321.             }
  322.         else if (cp0 + nchars < fText + fTextLen) {
  323.             cp0= cp0 + nchars;
  324.             cp= cp0;
  325.             }
  326.     } while (cp);
  327.     height= nlines * Nlm_LineHeight();
  328. }
  329.  
  330.  
  331. void DNotePanel::Draw()
  332. {
  333.     if (fText) {
  334.         Nlm_RecT area;
  335.         this->ViewRect( area);
  336.         Nlm_SelectFont(fFont);
  337.         Dgg_DrawTextbox( &area, fText, fTextLen, fJust, fDimmed); 
  338.         }
  339. }
  340.  
  341.  
  342. void DNotePanel::SetDim(Boolean isDim, Boolean redraw)  
  343. {
  344.     fDimmed= isDim;
  345.     if (redraw) this->Draw();
  346. }         
  347.  
  348. void DNotePanel::Enable()  
  349. {
  350.     fEnabled= true;
  351.     DPanel::Enable();
  352. }        
  353.  
  354. void DNotePanel::Disable()  
  355. {
  356.     fEnabled= false;
  357.     DPanel::Disable();
  358. }        
  359.  
  360.  
  361. void DNotePanel::Click(Nlm_PoinT mouse)
  362. {
  363.     if (fEnabled) {
  364.         Nlm_RecT area;
  365.         this->ViewRect( area);
  366.         Nlm_InvertRect( &area);
  367.     }
  368. }
  369.  
  370. void DNotePanel::Release(Nlm_PoinT mouse)
  371. {
  372.     if (fEnabled) {
  373.         Nlm_RecT area;
  374.         this->ViewRect( area);
  375.         Nlm_InvertRect( &area);
  376.         if (Nlm_PtInRect( mouse, &area)) {
  377.             // then button is "selected", otherwise not.
  378.             this->IsMyViewAction(this);
  379.             }
  380.         }
  381. }
  382.  
  383. void DNotePanel::Invalid(short newval, short oldval)
  384. {
  385. }
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392. //class DIconButton : public DPanel
  393.  
  394.  
  395. extern "C" void iconDrawProc(Nlm_IcoN item)
  396. {
  397.     DIconButton *obj= (DIconButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  398.     if (obj) obj->Draw();
  399. }
  400.  
  401. extern "C" void iconInvalProc(Nlm_IcoN item, Nlm_Int2 newval, Nlm_Int2 oldval)
  402. {
  403.     DIconButton *obj= (DIconButton*) Nlm_GetObject( (Nlm_GraphiC)item);
  404.     if (obj) obj->Invalid(newval, oldval);
  405. }
  406.  
  407. extern "C" void iconClickProc(Nlm_IcoN item, Nlm_PoinT mouse)
  408. {
  409.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  410.     if (obj) obj->Click(mouse);
  411. }
  412.  
  413. extern "C" void iconDragProc(Nlm_IcoN item, Nlm_PoinT mouse)
  414. {
  415.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  416.     if (obj) obj->Drag(mouse);
  417. }
  418.  
  419. extern "C" void iconHoldProc(Nlm_IcoN item, Nlm_PoinT mouse)
  420. {
  421.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  422.     if (obj) obj->Hold(mouse);
  423. }
  424.  
  425. extern "C" void iconReleaseProc(Nlm_IcoN item, Nlm_PoinT mouse)
  426. {
  427.     DPanel *obj= (DPanel*) Nlm_GetObject( (Nlm_GraphiC)item);
  428.     if (obj) obj->Release(mouse);
  429. }
  430.  
  431.  
  432.  
  433. // test this iconbutton frame !?
  434. enum {
  435.  kFInset= 2,
  436.  kFInset2= 4,
  437.  fFrame = 1
  438.  };
  439.  
  440. DIconButton::DIconButton(long id, DView* itsSuperior, DIcon* itsIcon):
  441.     DPanel( id, itsSuperior, 0, 0, subclasscreates),
  442.     fEnabled(true),
  443.     fIcon(itsIcon)
  444. {
  445.     short pixwidth, pixheight;
  446.     GetIconSize( pixwidth, pixheight);
  447.     fIconBut= Nlm_IconButton((Nlm_WindoW)itsSuperior->GetNlmObject(), pixwidth, pixheight, 
  448.             iconDrawProc, iconInvalProc, iconClickProc, iconDragProc, iconHoldProc, iconReleaseProc);
  449.     fPanel= (Nlm_PaneL) fIconBut;
  450.     this->SetNlmObject(fIconBut);    
  451. }
  452.  
  453. void DIconButton::GetIconSize(short& pixwidth, short& pixheight) 
  454. {
  455.     if (fIcon) {
  456.         pixwidth= fIcon->fWidth;
  457.         pixheight= fIcon->fHeight;
  458.         }
  459.     else {
  460.         pixwidth= 16;
  461.         pixheight= 16;
  462.         }
  463.     if (fFrame) {  
  464.         pixwidth  += kFInset2;
  465.         pixheight += kFInset2;
  466.         }
  467. }
  468.  
  469. void DIconButton::SetIcon(DIcon* itsIcon, Boolean redraw) 
  470.     Nlm_RecT area;
  471.     fIcon= itsIcon; 
  472.     short pixwidth, pixheight;
  473.     GetIconSize( pixwidth, pixheight);
  474.     this->ViewRect(area);
  475.     area.right = area.left + pixwidth;
  476.     area.bottom= area.top + pixheight;
  477.     this->RegisterRect( area);
  478.     if (redraw) InvalRect( area);
  479. }
  480.  
  481. void DIconButton::Enable()  
  482. {
  483.     if (!fEnabled) { 
  484.         fEnabled= true;
  485.         Invalidate();
  486.         DPanel::Enable();
  487.         }
  488. }        
  489.  
  490. void DIconButton::Disable()  
  491. {
  492.     if (fEnabled) {
  493.         fEnabled= false;
  494.         Invalidate();
  495.         DPanel::Disable();
  496.         }
  497. }        
  498.  
  499. void DIconButton::Draw()
  500. {
  501.     if (fIcon) {
  502.         Nlm_RecT area;
  503.         this->ViewRect( area);
  504.             // gray is usable only on color/grayscale monitors
  505.         if (!fEnabled) Nlm_LtGray(); 
  506.         if (fFrame) {  
  507.             //Nlm_WidePen(2);
  508.              Nlm_FrameRoundRect( &area, 8, 8);
  509.             Nlm_InsetRect( &area, kFInset, kFInset);
  510.             }
  511.         fIcon->Draw( area);
  512.         if (!fEnabled) Nlm_Black();
  513.         }
  514. }
  515.  
  516.  
  517.         // ?? should Invert() be a general DView method ??
  518. void DIconButton::Click(Nlm_PoinT mouse)
  519. {
  520.     if (fEnabled) {
  521.         Nlm_RecT area;
  522.         this->ViewRect( area);
  523.         if (fFrame) Nlm_InsetRect( &area, kFInset, kFInset);
  524.         Nlm_InvertRect( &area);
  525.         }
  526. }
  527.  
  528. void DIconButton::Release(Nlm_PoinT mouse)
  529. {
  530.     if (fEnabled) {
  531.         Nlm_RecT area;
  532.         this->ViewRect( area);
  533.         if (fFrame) Nlm_InsetRect( &area, kFInset, kFInset);
  534.         Nlm_InvertRect( &area);
  535.         if (Nlm_PtInRect( mouse, &area)) {
  536.             // then button is "selected", otherwise not.
  537.             this->IsMyViewAction(this);
  538.             }
  539.         }
  540. }
  541.  
  542.  
  543. void DIconButton::Invalid(short newval, short oldval)
  544. {
  545. }
  546.  
  547.  
  548.  
  549.  
  550.  
  551. //class DSlatePanel : public DPanel
  552.  
  553.  
  554.  
  555.  
  556. //class DSlate : public DView
  557.  
  558. extern "C" void slateScrollProc(Nlm_BaR sb, Nlm_SlatE s, short newval, short oldval)
  559. {
  560.     DScrollBar *obj= (DScrollBar*) Nlm_GetObject( (Nlm_GraphiC)sb);
  561.     DSlate *scrollee= (DSlate*) Nlm_GetObject( (Nlm_GraphiC)s);
  562.     if (obj) obj->Scroll(scrollee, newval, oldval);
  563. }
  564.  
  565. extern "C" void slateCharProc(Nlm_SlatE s, Nlm_Char c)
  566. {
  567.     DSlate *obj= (DSlate*) Nlm_GetObject( (Nlm_GraphiC)s);
  568.     if (obj) obj->CharHandler(c);
  569. }
  570.  
  571.     
  572. DSlate::DSlate(long id, DView* itsSuperior, short width, short height, SlateKind kind) :
  573.         DView( id, NULL, kSlate, itsSuperior) 
  574. {
  575.     switch (kind) {
  576.         case scrolling:
  577.             fSlate= Nlm_ScrollSlate((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height); 
  578.             break;
  579.         case normal:
  580.             fSlate= Nlm_NormalSlate((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height); 
  581.             break;
  582.         case hidden:
  583.             fSlate= Nlm_HiddenSlate((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height); 
  584.             break;
  585.         case general:
  586.             fSlate= Nlm_GeneralSlate((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, 
  587.                                 slateScrollProc, 0/*extra*/, NULL/*classPtr*/); 
  588.             break;
  589.     
  590.         }
  591.     this->SetNlmObject(fSlate);    
  592. }
  593.  
  594. void DSlate::VirtualSlate( short before, short after) 
  595. {
  596.     Nlm_VirtualSlate( fSlate, before, after, slateScrollProc);
  597. }
  598.  
  599. void DSlate::SetCharHandler() 
  600. {
  601.     Nlm_SetSlateChar( fSlate, slateCharProc);
  602. }
  603.  
  604. void DSlate::CharHandler(char c) 
  605. {
  606. }
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615. //class DDisplay : public DView    
  616.  
  617. DDisplay::DDisplay(long id, DView* itsSuperior, short width, short height, DisplayKind kind):
  618.     DView( id, NULL, kDisplay, itsSuperior) 
  619. {
  620.     switch (kind) {
  621.         case normal:
  622.             fDisplay= Nlm_NormalDisplay((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height);
  623.             break;
  624.         case scrolling:
  625.             fDisplay= Nlm_ScrollDisplay((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height);
  626.             break;
  627.         }
  628.     this->SetNlmObject(fDisplay);    
  629. }
  630.     
  631.  
  632.  
  633.  
  634.  
  635. //class DDocPanel : public DPanel
  636.  
  637. #if 0
  638. typedef CharPtr (*DocPrntProc)  PROTO((Pointer));
  639. typedef void    (*DocClckProc)  PROTO((DoC, PoinT));
  640. typedef void    (*DocDrawProc)  PROTO((DoC, RectPtr, Int2, Int2));
  641. typedef Boolean (*DocShadeProc) PROTO((DoC, Int2, Int2, Int2));
  642. typedef void    (*DocDataProc)  PROTO((DoC, Pointer));
  643. typedef void    (*DocPanProc)   PROTO((DoC));
  644. typedef void    (*DocFreeProc)  PROTO((DoC, VoidPtr));
  645. #endif
  646.  
  647.  
  648. DDocPanel::DDocPanel(long id, DView* itsSuperior, short pixwidth, short pixheight):
  649.         DPanel(id, itsSuperior, pixwidth, pixheight, DPanel::subclasscreates) 
  650. {
  651.     fDocpanel= Nlm_DocumentPanel( (Nlm_WindoW)itsSuperior->GetNlmObject(), pixwidth, pixheight);
  652.     fPanel= (Nlm_PaneL) fDocpanel;
  653.     Nlm_SetPanelClick(fPanel, panelClickProc, panelDragProc, panelHoldProc, panelReleaseProc);
  654.     this->SetNlmObject(fDocpanel);
  655.     this->SetAutoAdjust(true); // used after append/insert/replace/delete
  656.  
  657.     DWindow* win= this->GetWindow();
  658.     if (win) {
  659.         win->fPrintHandler= this;
  660.         win->fSaveHandler= this;
  661.         }
  662.     
  663.     //Nlm_SetDocProcs(fDocpanel DocClckProc click, DocClckProc drag, DocClckProc release, DocPanProc pan);
  664.     //Nlm_SetDocShade(fDocpanel, DocDrawProc draw, DocShadeProc gray, DocShadeProc invert, DocShadeProc color));
  665. }
  666.     
  667. DDocPanel::~DDocPanel()
  668. {
  669.     //?? need for SetDocData's DocFreeProc call...
  670. }
  671.     
  672. void     DDocPanel::SetData(void* data)
  673. {
  674.     //Nlm_SetDocData(fDocpanel, data, DocFreeProc cleanup); 
  675. }
  676.  
  677. char* DDocPanel::DataToChar(Pointer ptr)  // this is vibrant-document.h CharPrtProc()
  678. {
  679.   if (ptr != NULL) {
  680.     return Nlm_StringSave ((char*)ptr);
  681.   } else {
  682.     return NULL;
  683.   }
  684. }
  685.  
  686. void     DDocPanel::Append( Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  687.                 Nlm_FonT font, Boolean docOwnsData)
  688. {
  689.     Nlm_AppendItem(fDocpanel, NULL/*data2char*/, data, docOwnsData, lines, parFormat, colFormat, font);
  690. }
  691.  
  692.  
  693. void     DDocPanel::Replace( short item, Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  694.                 Nlm_FonT font, Boolean docOwnsData)
  695. {
  696.     // need &DDocPanel::DataToChar in C form (but no object ref to call back !)
  697.     //from: char *(DDocPanel::*Cpp func)(void *) -to-> char *(*C func)(void *)
  698.     Nlm_ReplaceItem(fDocpanel, item, NULL/*data2char*/, data, docOwnsData, lines, parFormat, colFormat, font);
  699. }
  700.  
  701.  
  702. void     DDocPanel::Insert( short item, Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  703.                 Nlm_FonT font, Boolean docOwnsData)
  704. {
  705.     Nlm_InsertItem(fDocpanel, item, NULL/*data2char*/, data, docOwnsData, lines, parFormat, colFormat, font);
  706. }
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.